package com.tencent.wxcloudrun.controller.fangdong;

import com.tencent.wxcloudrun.config.ApiResponse;
import com.tencent.wxcloudrun.pojo.dto.req.SetHomeListToHelpMateReq;
import com.tencent.wxcloudrun.pojo.dto.resp.GetHelpMateListResp;
import com.tencent.wxcloudrun.pojo.dto.resp.GetLandlordInfoResp;
import com.tencent.wxcloudrun.pojo.dto.resp.HelpMateGetHomeListResp;
import com.tencent.wxcloudrun.service.business.fangdong.HelpMateService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 房东增加对助理的管理<br>
 * 一个房东可以有多个助理。一个助理，只能是某一个房东的助理。某人如果是房东，则他不能当助理
 */
@RestController
@RequestMapping("helpMate")
@Validated
public class HelpMateController {

    @Resource
    private HelpMateService helpMateService;

    /**
     * 获取成为助理的编号，这个只有房东才能进行生成
     */
    @GetMapping("getNum")
    public ApiResponse<String> getNum() {
        return new ApiResponse<>(helpMateService.getNum());
    }

    /**
     * 用户输入编号与昵称后可成为助理。
     */
    @GetMapping("beHelp")
    public ApiResponse<String> beHelp(@NotBlank(message = "编号不能为空") @RequestParam("num") String num,
                                      @NotBlank(message = "昵称不能为空") @RequestParam("alias") String alias,
                                      @NotBlank(message = "电话不能为空") @RequestParam("phone") String phone) {
        return new ApiResponse<>(helpMateService.beHelp(num, alias, phone));
    }

    /**
     * 修改昵称
     */
    @GetMapping("updateName")
    public ApiResponse<String> updateName(@RequestParam("id") String id,
                                          @NotBlank(message = "别称不能为空") @RequestParam("alias") String alias,
                                          @NotBlank(message = "电话不能为空") @RequestParam("phone") String phone) {
        return new ApiResponse<>(helpMateService.updateName(id, alias, phone));
    }

    /**
     * 房东获取助理列表
     */
    @GetMapping("getHelpMateList")
    public ApiResponse<List<GetHelpMateListResp>> getHelpMateList() {
        return new ApiResponse<>(helpMateService.getHelpMateList());
    }

    @GetMapping("delMate")
    public ApiResponse<String> delMate(@NotBlank(message = "助理id不能为空") @RequestParam("id") String id) {
        return new ApiResponse<>(helpMateService.delMate(id));
    }

    /**
     * 获取房屋列表
     */
    @GetMapping("/getHomeList")
    public ApiResponse<List<HelpMateGetHomeListResp>> getHomeList(@NotBlank(message = "助理id不能为空") @RequestParam("id") String id) {
        return new ApiResponse<>(helpMateService.getHomeList(id));
    }

    /**
     * 确认添加这一些房屋给这个助理
     */
    @PostMapping("setHomeListToHelpMate")
    public ApiResponse<String> setHomeListToHelpMate(@RequestBody SetHomeListToHelpMateReq req) {
        return new ApiResponse<>(helpMateService.setHomeListToHelpMate(req));
    }

    /**
     * 助理查看房东信息
     */
    @GetMapping("getLandlordInfo")
    public ApiResponse<GetLandlordInfoResp> getLandlordInfo() {
        return new ApiResponse<>(helpMateService.getLandlordInfo());
    }

    /**
     * 助理取消与房东的绑定关系
     */
    @GetMapping("unbindLandlord")
    public ApiResponse<String> unbindLandlord() {
        return new ApiResponse<>(helpMateService.unbindLandlord());
    }

}
